var http=require('http'),qs=require('querystring');

var names=process.argv.slice(2).join(' ').trim();


if(!names.length){
    console.log('No search term');
}else{
    console.log('Search names:',names);
    var req=http.request({
        host:'localhost',
        port:3000,
        path:'/?'+qs.stringify({names:names}),
        method:'GET'
    }, function (res) {
        var body='';
        res.on('data', function (chunk) {
            body+=chunk;
        });
        res.on('end', function () {
            console.log('body:',body);
            var html='';
            JSON.parse(body).list.forEach(function(user){
                html+='name:'+user.name+'\n';
            });
            console.log('html:');
            console.log(html);
        });
    });
    req.end();
}


